package org.example.visitor;

import java.util.ArrayList;
import java.util.List;

public class SuperMarket {
    List<IProduct> products = new ArrayList<>();

    SuperMarket(){
        ChairProduct chair = new ChairProduct(10,"red");
        DeskProduct desk = new DeskProduct(30,"white");
        ComputerProduct computer = new ComputerProduct(10000, "black");
        products.add(chair);
        products.add(desk);
        products.add(computer);
    }

    /**
     * 这里很奇妙,代码是同一个,但是随着访问者的不同会输出不同的内容
     * @param visitor
     */
    public void accept(IVisitor visitor){
        products.forEach(p->p.accept(visitor));
    }

}
